package org.digitaldomination.speedclicker;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebView;
import android.widget.Button;

public class highscore extends Activity {
	int count = 1;
	Button goback;
	SQLiteDatabase scoreDB;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.highscore);
		Button goback = (Button) findViewById(R.id.backs);
		goback.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				Intent intent = new Intent();
                setResult(RESULT_OK, intent);
				finish();
			}
		});
		WebView webview = (WebView) findViewById(R.id.webview);
       StringBuilder builder = new StringBuilder();
        builder.append("<html><body><h1>High Scores</h1><table>");
		connectdb();
		Cursor cursor  = scoreDB.rawQuery("SELECT * FROM highscore ORDER BY SCORE DESC", null);
        if (cursor != null)
        {
            if (cursor.moveToFirst())
            {
                do
                {
                     builder.append("<tr><td>");
                     builder.append(cursor.getString(1));
                     builder.append("</td><td>");
                     builder.append(cursor.getString(2));
                     builder.append("</td></tr>");
                } while (cursor.moveToNext());
            }
            cursor.close();
        }
        scoreDB.close();
        builder.append("</table></html>");
        webview.loadData(builder.toString(), "text/html", "UTF-8");
	}
    protected void connectdb() {
   	 scoreDB = openOrCreateDatabase("highscore.db", SQLiteDatabase.CREATE_IF_NECESSARY | SQLiteDatabase.OPEN_READWRITE, null);
   	 scoreDB.execSQL("CREATE TABLE IF  NOT EXISTS highscore (ID INTEGER PRIMARY KEY, NAME TEXT, SCORE INTEGER);");
}
    
}
